package channelEvent

import "time"

type Event struct {
	ch chan string
}

func New() *Event {
	ptr := &Event{}
	ptr.ch = make(chan string)
	return ptr
}

func (e *Event) Close() {
	close(e.ch)
	e.ch = nil
}

func (e *Event) Notify(message string) {
	e.ch <- message
}

func (e *Event) Wait(timeout int64) string {
	select {
	case message := <-e.ch:
		return message
	case <-time.After(time.Duration(timeout) * time.Millisecond):
		return ""
	}
}
